import request from "@/utils/request";
const VITE_APP_USER_URL = import.meta.env.VITE_APP_USER_URL;
/**
 * 获取图形验证码
 * http://192.168.88.247:4999/web/#/14/48
 * @returns
 */
export function getCodeImg(xzconfig?: any) {
  return request({
    xzconfig,
    url: VITE_APP_USER_URL + "/api/v1/refresh_captcha",
    method: "get"
  });
}

/**
 * 发送手机/邮箱验证码
 * http://192.168.88.247:4999/web/#/14/2173
 * @returns
 */
export function sendSms(data: any, xzconfig?: any) {
  return request({
    xzconfig,
    url: VITE_APP_USER_URL + "/api/v2/send_sms",
    method: "post",
    data
  });
}

/**
 * 检查手机验证码正确性
 * http://192.168.88.247:4999/web/#/14/129
 * @returns
 */
export function checkSms(params: any) {
  return request({
    url: VITE_APP_USER_URL + "/api/v1/check_sms",
    method: "GET",
    params
  });
}

/**
 * 登录
 * http://192.168.88.247:4999/web/#/105/789 访问密码: RR8pUR67
 * @returns
 */
export function login(data: any) {
  return request({
    url: "/api/v2/member/login",
    method: "post",
    data
  });
}

/**
 * 发送手机/邮箱验证码
 * http://192.168.88.247:4999/web/#/14/467
 * @returns
 */
export function getPartyParam(params: any) {
  return request({
    url: VITE_APP_USER_URL + "/api/v1/oath2_jsparam",
    method: "get",
    params
  });
}

/**
 * 账号绑定第一步
 * http://192.168.88.247:4999/web/#/14/748
 * @returns
 */
export function bindAuth(data: any) {
  data.auth_type === "wx" && (data.version = "v2");
  return request({
    url: VITE_APP_USER_URL + "/api/v1/bind/auth",
    method: "POST",
    data
  });
}

/**
 * 账号绑定第二步：合并账号
 * http://192.168.88.247:4999/web/#/14/748
 * @returns
 */
export function bindAuthMerge(data: any) {
  return request({
    url: VITE_APP_USER_URL + "/api/v1/bind/auth_merge",
    method: "POST",
    data
  });
}

/**
 * 检查用户是否已注册
 * http://192.168.88.247:4999/web/#/14/130
 * @returns
 */
export function checkUserIsExist (phonenumber: string | number, xzconfig?: any) {
  return request({
    xzconfig,
    baseURL: VITE_APP_USER_URL,
    url: '/api/v1/check_user',
    method: 'get',
    params: { phonenumber }
  })
}

/**
 * 注销登录
 * http://192.168.88.247:4999/web/#/14/49
 * @returns
 */
export function logout(params: any) {
  return request({
    baseURL: VITE_APP_USER_URL,
    url: "/api/v1/logout",
    method: "get",
    params
  });
}
export function getSecurePub() {
  return request({
    headers: { Secure: "HandShake" },
    url: "/api/v1/get_secure_pub",
    method: "get"
  });
}
/**
 * 用户设备选择性踢出
 * http://192.168.88.247:4999/web/#/14/1178
 * @returns
 */
export function delDevice(data: any) {
  return request({
    baseURL: VITE_APP_USER_URL,
    url: "/api/v1/device/multi_del",
    method: "post",
    data
  });
}

/**
 * token授权码转换
 * http://192.168.88.247:4999/web/#/14/47
 * @returns
 */
export function refreshToken(data: any) {
  return request({
    baseURL: VITE_APP_USER_URL,
    url: "/api/v1/exchanged_token",
    method: "post",
    data
  });
}
/**
 * 创建公众号二维码
 * http://192.168.88.247:4999/web/#/217/1784
 * e8UsVRQ9
 * @returns
 */
export function createGzhQrcode(data: any) {
  return request({
    baseURL: VITE_APP_USER_URL,
    url: "/api/v1/wx/qrcode/create",
    method: "post",
    data
  });
}
/**
 * 轮询用户信息
 * http://192.168.88.247:4999/web/#/217/1925
 * e8UsVRQ9
 * @returns
 */
export function checkGzhLogin(params: any) {
  return request({
    noMsg: true,
    baseURL: VITE_APP_USER_URL,
    url: "/api/v1/wx/user",
    method: "get",
    params
  });
}
/**
 * 更新用户密码
 * http://192.168.88.247:4999/web/#/14/51
 * @returns
 */
export function updatePwd(data: any, xzconfig?: any) {
  return request({
    xzconfig,
    url: VITE_APP_USER_URL + "/api/v1/update_pwd",
    method: "put",
    data
  });
}
/**
 * 注册
 * http://192.168.88.247:4999/web/#/14/46
 * @returns
 */
export function register(data: any, xzconfig?: any) {
  return request({
    xzconfig,
    url: "/api/v1/logon",
    method: "post",
    data
  });
}
export function userLogon(data: any, xzconfig?: any) {
  return request({
    xzconfig,
    noMsg: true,
    url: "/api/v1/user_logon",
    method: "post",
    data
  });
}
/**
 * 更新用户密码
 * http://192.168.88.247:4999/web/#/14/51
 * @returns
 */
export function upEmailPwd(data: any, xzconfig: any) {
  return request({
    xzconfig,
    noMsg: true,
    url: VITE_APP_USER_URL + "/api/v1/update_emailPwd",
    method: "put",
    data
  });
}

/**
 * 解除绑定
 * http://192.168.88.247:4999/web/#/14/702
 * @returns
 */
export function oath2Unbind(data: any) {
  return request({
    url: VITE_APP_USER_URL + "/api/v1/oath2_unbind",
    method: "DELETE",
    data
  });
}
